﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using WebChatApi.Common.Interface;

/// <summary>
/// The Common namespace.
/// </summary>
namespace WebChatApi.Common
{
    /// <summary>
    /// Class for basic criteria information.
    /// </summary>
    [DataContract]
    public class BaseCriteria
    {
        #region Properties

        /// <summary>
        /// Gets or sets the key.
        /// </summary>
        /// <value>The key.</value>
        [DataMember]
        public Guid? Key
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the stamp for the start of time scope.
        /// This value is as same as value in property <c>FromStampString</c>.
        /// And this property will be used to business logics and WCF XML serialization.
        /// So if you are using JSON format, please use <c>FromStampString</c>.
        /// </summary>
        /// <value>From stamp.</value>
        [DataMember]
        public DateTime? FromStamp
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets from stamp string.
        /// Format: yyyy-MM-ddTHH:mm:ss.fffzzz
        /// Sample: 2013-01-02T03:45:23.215+08:00
        /// This value is as same as value in property <c>FromStamp</c>.
        /// And this property will be only used to JSON format serialization.
        /// So if the property is used to business logics and WCF XML serialization, please use <c>FromStamp</c>.
        /// </summary>
        /// <value>From stamp string.</value>
        public string FromStampString
        {
            get
            {
                return this.FromStamp == null ? string.Empty : DateTimeUtil.DateTimeToFullString(this.FromStamp.Value);
            }
            set
            {
                this.FromStamp = string.IsNullOrWhiteSpace(value) ? null : DateTimeUtil.FullStringToDateTime(value, this.FromStamp == null ? DateTime.MinValue : this.FromStamp.Value) as DateTime?;
            }
        }

        /// <summary>
        /// Gets or sets the stamp for the end of time scope.
        /// This value is as same as value in property <c>ToStampString</c>.
        /// And this property will be used to business logics and WCF XML serialization.
        /// So if you are using JSON format, please use <c>ToStampString</c>.
        /// </summary>
        /// <value>To stamp.</value>
        [DataMember]
        public DateTime? ToStamp
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets from stamp string.
        /// Format: yyyy-MM-ddTHH:mm:ss.fffzzz
        /// Sample: 2013-01-02T03:45:23.215+08:00
        /// This value is as same as value in property <c>ToStamp</c>.
        /// And this property will be only used to JSON format serialization.
        /// So if the property is used to business logics and WCF XML serialization, please use <c>ToStamp</c>.
        /// </summary>
        /// <value>From stamp string.</value>
        public string ToStampString
        {
            get
            {
                return this.ToStamp == null ? string.Empty : DateTimeUtil.DateTimeToFullString(this.ToStamp.Value);
            }
            set
            {
                this.ToStamp = string.IsNullOrWhiteSpace(value) ? null : DateTimeUtil.FullStringToDateTime(value, this.ToStamp == null ? DateTime.MinValue : this.ToStamp.Value) as DateTime?;
            }
        }


        /// <summary>
        /// Gets or sets the count.
        /// </summary>
        /// <value>The count.</value>
        [DataMember]
        public int Count
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the page.
        /// NOTE:
        /// This property may not be applied all query operations. Please ask developers for whether the query is supported for Page property.
        /// </summary>
        /// <value>The page.</value>
        [DataMember]
        public int Page
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the keyword.
        /// </summary>
        /// <value>The keyword.</value>
        [DataMember]
        public string Keyword
        {
            get;
            set;
        }

        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="BaseCriteria" /> class.
        /// </summary>
        public BaseCriteria()
        {
            this.Key = Guid.NewGuid();
        }

        #endregion
    }
}
